MOD = 998244353


def frac(max_n):
    fact = [1] * (max_n + 1)
    for i in range(1, max_n + 1):
        fact[i] = (fact[i-1]% MOD * i % MOD)% MOD
    return fact

def solve(n, a, fact):

    x = 0
    for val in a:
        x |= val
    
    m = sum(1 for val in a if val == x)
    
    if n == 1:  
        result = m
    elif n == 2:
        result = m * (m-1) % MOD
    else:
        result = m * (m-1) % MOD * fact[n-2] % MOD
    
    return result

def main():
    max_n = 2 * 10**5 +3
    fact = frac(max_n)
    
    
    t = int(input())
    for _ in range(t):
        n = int(input())
        a = list(map(int, input().split()))
        result = solve(n, a, fact)
        print(result)

if __name__ == "__main__":
    main()